package Zoo.Handler;


/**
 * 动物饲养员删除动物信息
 */


import Zoo.Entity.AnimalEntity;
import Zoo.Impl.ZoomenService1Impl;
import Zoo.Service.ZoomenService1;
import Zoo.View.ZoomanView.DeleteAnimalView;
import Zoo.View.ZoomanView.ZoomenView1;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DeleteAnimalViewHandler implements ActionListener {
    private DeleteAnimalView deleteAnimalView;
    private ZoomenView1 zoomenView1;


    public DeleteAnimalViewHandler(DeleteAnimalView deleteAnimalView, ZoomenView1 zoomenView1) {
        this.deleteAnimalView=deleteAnimalView;
        this.zoomenView1=zoomenView1;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text =jButton.getText();
        if("删除".equals(text)){
            ZoomenService1 zoomenService1=new ZoomenService1Impl();
            AnimalEntity animalEntity =deleteAnimalView.buildDeletedAnimalEntity();
            boolean deleteResult=zoomenService1.delete(animalEntity);
            if(deleteResult){
                //重新加载表格查到最新数据
                zoomenView1.reloadTable();
                deleteAnimalView.dispose();
            }else{
                JOptionPane.showMessageDialog(deleteAnimalView,"修改失败");

            }

        }
    }

}
